(import
 (except (rnrs base) map)
 (only (guile)
       lambda* λ
       ;; ports
       current-output-port
       simple-format)
 ;; SRFI 64 - unit testing forms
 (srfi srfi-64)
 ;; SRFI 43 - vector procs
 (srfi srfi-43)
 ;; SRFI 1 - list procs
 (srfi srfi-1)
 ;; third party
 (json)
 ;; tested module
 (fslib)
 (vocabulary-data)
 (search)
 (json-reader))


(define test-vocabulary
  (get-json-from-file
   (fsing-join "test" "data" "test-vocabulary.json")))

(test-begin "vocabulary-data-test")

(test-group
 "search-in-vocabulary-entry-attributes"

 (test-equal "search-in-vocabulary-entry-attributes - 01"
   #t
   (let ([voc-entry (get:vocabulary/nth-entry test-vocabulary 2)])
     (let ([metadata (get:entry/metadata voc-entry)])
       (search-in-vocabulary-entry-attributes
        metadata
        "tag2"
        #:equal-test? (make-general-comparator)
        #:attribute-test?
        (λ (attr)
          (member (get:attribute/key attr)
                  '("tags" "explanations")))))))

 (test-equal "search-in-vocabulary-entry-attributes - 01"
   #f
   (let ([voc-entry (get:vocabulary/nth-entry test-vocabulary 2)])
     (let ([translation-data (get:entry/translation-data voc-entry)])
       (search-in-vocabulary-entry-attributes
        translation-data
        "tag2"
        #:equal-test? (make-general-comparator)
        #:attribute-test?
        (λ (attr)
          (member (get:attribute/key attr)
                  '("tags" "explanations"))))))))

(test-group
 "vocabulary-search"

 (test-equal "vocabulary-search attribute selection - 01"
   3
   (vector-length
    (vocabulary-search test-vocabulary
                       "tag2"
                       #:equal-test? (make-general-comparator)
                       #:attribute-test?
                       (λ (attr)
                         (member (get:attribute/key attr)
                                 '("tags" "explanations"))))))

 (test-equal "vocabulary-search attribute selection - 02"
   1
   (vector-length
    (vocabulary-search test-vocabulary
                       "tag3"
                       #:equal-test? (make-general-comparator)
                       #:attribute-test?
                       (λ (attr)
                         (member (get:attribute/key attr)
                                 '("tags" "explanations")))))))

;; Finish the testsuite, and report results.
(test-end "vocabulary-data-test")
